--Simple Factory
--[[
	简单工厂：（创建型）
	作用：将不同类型的生产集中到同一位置
	使用场景：对象创建不算复杂，且变化不大的时候。
--]]

require 'Class'

--敌人类型
EnemyType = {
	Lv1 = 1,
	Lv2 = 2,
	Boss = 3,
	NUM = 4,
}

IEnemy = Class()  --敌人接口

Enemy_Lv1 = Class(IEnemy)
Enemy_Lv1.Attack = function(self)
	print(string.format('%s正在进行攻击',self.Name))
end
Enemy_Lv2 = Class(IEnemy)
Enemy_Lv2.Attack = function(self)
	print(string.format('%s正在进行攻击',self.Name))
end
Enemy_Boss = Class(IEnemy)
Enemy_Boss.Attack = function(self)
	print(string.format('%s正在进行攻击',self.Name))
end

SimpleFactory = Class()  --简单工厂
SimpleFactory.Create = function(self,enemyType)
	if enemyType == EnemyType.Lv1 then
		return Enemy_Lv1:New({Name = '等级1的敌人'})
	elseif enemyType == EnemyType.Lv2 then
		return Enemy_Lv2:New({Name = '等级2的敌人'})
	elseif enemyType == EnemyType.Boss then
		return Enemy_Boss:New({Name = 'Boss'})
	end
end

--------Main--------
function main()
	simpleFactory = SimpleFactory:New()
	enemy_Lv1 = simpleFactory:Create(EnemyType.Lv1)
	enemy_Boss = simpleFactory:Create(EnemyType.Boss)
	enemy_Lv1:Attack()
	enemy_Boss:Attack()
end

main()